﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Lab1.QuestionSpace
{
    /// <summary>
    /// Interaction logic for Edit.xaml
    /// </summary>
    public partial class Edit : Page
    {
        private QuestionService qService = new QuestionService();
        public Edit(Question question)
        {
            InitializeComponent();
            QuestionCreateGrid.DataContext = question;
        }

        private void Save(object sender, RoutedEventArgs e)
        {
            Question question = (Question)QuestionCreateGrid.DataContext;
            if (question.Root == true && qService.getRoot() != null)
            {
                if (!qService.getRoot().Id.Equals(question.Id))
                {
                    MessageBox.Show("В бд уже есть корневой вопрос!");
                    return;
                }
                else
                {
                    qService.update(question);
                    this.NavigationService.Navigate(new Index());

                }
            }
            qService.update(question);
            this.NavigationService.Navigate(new Index());
        }
    }
}
